//: Playground - noun: a place where people can play

import UIKit

//字典定义

var airport = ["TYO":"Tokyo","DUB":"Dublin"]

airport["LHR"] = "London"
airport.count
airport["LHR"] = "London Heathrow"

//可以使用下标语法把他的值分配为nil，来移除这个键值对
airport["DUB"] = nil
airport.count
if let airportName = airport["DUB"] {
    
    print("The name of the airport is \(airportName)")
    
}else{
    
    print("That airoirt is not in the airports dictionary.")
}

for (airportCode,airportName) in airport{
    
    print("\(airportCode):\(airportName)")
    
}

for tuples in airport{
    
    print("键：\(tuples.0) 值：\(tuples.1)")
    
}

 let keys = airport.keys
  print(keys)
  print(Array(airport.values))

//方法返回更新值之前的原值。这样方便我们检查更新是否成功
 airport.updateValue("budlin", forKey: "TYO")
 airport.removeAll(keepCapacity: true)
 airport.removeAll()

